﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace UFSSServerClasses
{
    public static class SystemAccess
    {
        public static string getSystemStat(string property, bool isLimit = false)
        {
            Dictionary<string, long> results = getSystemStats();

            try
            {
                if (isLimit)
                    return results[property + "Limit"].ToString();
                return results[property + "Value"].ToString();
            }
            catch
            {
                return null;
            }
        }
        public static bool LimitPassed(double value, double limit)
        {

            return true;
        }
        public static Dictionary<string, long> getSystemStats()
        {
            Dictionary<string, long> results = new Dictionary<string,long>(3);
            try
            {
                using (SqlConnection connection = new SqlConnection(DBAccess.getConString()))
                {
                    connection.Open();
                    SqlCommand c = new SqlCommand("getsystemstats", connection);
                    c.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlDataReader r = c.ExecuteReader();
                    while (r.Read())
                    {
                        results[r.GetString(1) + "Value"] = r.GetInt64(2);
                        results[r.GetString(1) + "Limit"] = r.GetInt64(3);
                    }
                    connection.Close();
                    return results;
                }
            }
            catch
            {
                return null;
            }
        }

    }
}
